package com.wish.g01.financial.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wish.g01.base.entity.JrProduct;
import com.wish.g01.base.service.IJrProductService;
import com.wish.g01.common.core.web.page.TableDataInfo;
import com.wish.g01.common.security.annotation.PreAuthorize;
import com.wish.g01.financial.common.AjaxResult;
import com.wish.g01.financial.dto.AppDto;
import com.wish.g01.financial.dto.FinancialDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品查询
 * 这个类的作者是13536
 * 开发日期:2022/5/31
 **/
@RestController
@RequestMapping("applyState")
public class ApplyStateController {

    @Autowired
   private IJrProductService iJrProductService;

    @PreAuthorize(hasPermi = "financial:applyState:list")
    @GetMapping("list")
    public AjaxResult getProductList(FinancialDto financialDto){
        QueryWrapper<JrProduct> jrProductQueryWrapper = new QueryWrapper<>();
        jrProductQueryWrapper.eq("jr_product_type",financialDto.getJrProductType());
        jrProductQueryWrapper.in("apply_state",0,2);
        List<JrProduct> list = iJrProductService.list(jrProductQueryWrapper);
        return AjaxResult.success(list);
    }

    @PostMapping("appState")
    public AjaxResult getAppState(@RequestBody AppDto appDto){
        JrProduct byId = iJrProductService.getById(appDto.getId());
//        System.out.println("q111"+byId);
        JrProduct jrProduct = byId.setApplyState(1);
        boolean update = iJrProductService.saveOrUpdate(byId);
        if(update){
            return  AjaxResult.success("审核通过");
        }
       return AjaxResult.error("审核未通过");
    }

    @PostMapping("delectable")
    public AjaxResult delectable(@RequestBody AppDto appDto){
        JrProduct byId = iJrProductService.getById(appDto.getId());
        JrProduct jrProduct = byId.setApplyState(2);
        boolean update = iJrProductService.saveOrUpdate(byId);
        if(update){
            return  AjaxResult.success("驳回");
        }
        return AjaxResult.error("错误");
    }

}
